<?php
session_start();

require_once '../header.php';
?>
    <!doctype html>
    <html>

    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>海报表单</title>
        <meta name="description" content="这是一个 index 页面">
        <meta name="keywords" content="index">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="renderer" content="webkit">
        <meta http-equiv="Cache-Control" content="no-siteapp"/>
        <link rel="icon" type="image/png" href="assets/i/favicon.png">
        <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
        <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
        <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
        <link rel="stylesheet" href="assets/css/admin.css">
        <link rel="stylesheet" href="assets/css/app.css">
    </head>

    <body data-type="generalComponents">


    <header class="am-topbar am-topbar-inverse admin-header">
        <div class="am-topbar-brand">
            <a href="javascript:;" class="tpl-logo">
                <img src="assets/img/logo.png" alt="">
            </a>
        </div>
        <div class="am-icon-list tpl-header-nav-hover-ico am-fl am-margin-right">

        </div>

        <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only"
                data-am-collapse="{target: '#topbar-collapse'}">
            <span class="am-sr-only">导航切换</span>
            <span class="am-icon-bars"></span>
        </button>

        <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

            <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list tpl-header-list">
                <li class="am-dropdown" data-am-dropdown data-am-dropdown-toggle>
                    <a class="am-dropdown-toggle tpl-header-list-link" href="javascript:;">
                        <span class="am-icon-bell-o"></span> 新消息 <span
                                class="am-badge tpl-badge-success am-round">5</span></span>
                    </a>
                    <ul class="am-dropdown-content tpl-dropdown-content">
                        <li class="tpl-dropdown-content-external">
                            <h3>你有 <span class="tpl-color-success">5</span> 条新消息</h3><a href="###">全部</a></li>
                        <li class="tpl-dropdown-list-bdbc">
                            <a href="#" class="tpl-dropdown-list-fl">
                                <span class="am-icon-btn am-icon-plus tpl-dropdown-ico-btn-size tpl-badge-success"></span>
                                【预览模块】移动端 查看时 手机、电脑框隐藏。
                            </a>
                            <span class="tpl-dropdown-list-fr">3小时前</span>
                        </li>
                        <li class="tpl-dropdown-list-bdbc">
                            <a href="#" class="tpl-dropdown-list-fl">
                                <span class="am-icon-btn am-icon-check tpl-dropdown-ico-btn-size tpl-badge-danger"></span>
                                移动端，导航条下边距处理
                            </a>
                            <span class="tpl-dropdown-list-fr">15分钟前</span>
                        </li>
                        <li class="tpl-dropdown-list-bdbc">
                            <a href="#" class="tpl-dropdown-list-fl">
                                <span class="am-icon-btn am-icon-bell-o tpl-dropdown-ico-btn-size tpl-badge-warning"></span>
                                追加统计代码
                            </a>
                            <span class="tpl-dropdown-list-fr">2天前</span>
                        </li>
                    </ul>
                </li>
                <li class="am-hide-sm-only">
                    <a href="javascript:;" id="admin-fullscreen" class="tpl-header-list-link">
                        <span class="am-icon-arrows-alt"></span>
                        <span class="admin-fullText">开启全屏</span>
                    </a>
                </li>

                <li class="am-dropdown" data-am-dropdown data-am-dropdown-toggle>
                    <a class="am-dropdown-toggle tpl-header-list-link" href="javascript:;">
                        <span class="tpl-header-list-user-nick"><?= $_SESSION['username'] ?></span>
                        <span class="tpl-header-list-user-ico"><img src="assets/img/user01.png"></span>
                    </a>
                    <ul class="am-dropdown-content">
                        <li><a href="#"><span class="am-icon-bell-o"></span> 资料</a></li>
                        <li><a href="#"><span class="am-icon-cog"></span> 设置</a></li>
                        <li><a href="#"><span class="am-icon-power-off"></span> 退出</a></li>
                    </ul>
                </li>
                <li>
                    <a href="###" class="tpl-header-list-link">
                        <span class="am-icon-sign-out tpl-header-list-ico-out-size"></span>
                    </a>
                </li>
            </ul>
        </div>
    </header>


    <div class="tpl-page-container tpl-page-header-fixed">


        <div class="tpl-left-nav tpl-left-nav-hover">
            <div class="tpl-left-nav-title">
                功能 列表
            </div>
            <div class="tpl-left-nav-list">
                <ul class="tpl-left-nav-menu">
                    <li class="tpl-left-nav-item">
                        <a href="index.php" class="nav-link active">
                            <i class="am-icon-home"></i>
                            <span>首页</span>
                        </a>
                    </li>

                    <li class="tpl-left-nav-item">
                        <!-- 打开状态 a 标签添加 active 即可   -->
                        <a href="javascript:;" class="nav-link tpl-left-nav-link-list active">
                            <i class="am-icon-table"></i>
                            <span>表格</span>
                            <!-- 列表打开状态的i标签添加 tpl-left-nav-more-ico-rotate 图表即90°旋转  -->
                            <i class="am-icon-angle-right tpl-left-nav-more-ico am-fr am-margin-right tpl-left-nav-more-ico-rotate"></i>
                        </a>
                        <ul class="tpl-left-nav-sub-menu" style="display:block">
                            <li>
                                <!-- 打开状态 a 标签添加 active 即可   -->
                                <a href="table-font-list.php" class="active">
                                    <i class="am-icon-angle-right"></i>
                                    <span>文字表格</span>
                                    <i class="am-icon-star tpl-left-nav-content-ico am-fr am-margin-right"></i>
                                </a>

                                <a href="table-images-list.php">
                                    <i class="am-icon-angle-right"></i>
                                    <span>图片表格</span>
                                    <i class="tpl-left-nav-content tpl-badge-success">
                                        18
                                    </i>

                                    <a href="form-news.php">
                                        <i class="am-icon-angle-right"></i>
                                        <span>消息列表</span>
                                        <i class="tpl-left-nav-content tpl-badge-primary">
                                            5
                                        </i>

                            </li>
                        </ul>
                    </li>

                    <li class="tpl-left-nav-item">
                        <a href="login.php" class="nav-link tpl-left-nav-link-list">
                            <i class="am-icon-key"></i>
                            <span>登录</span>

                        </a>
                    </li>
                </ul>
            </div>
        </div>


        <div class="tpl-content-wrapper">
            <div class="tpl-content-page-title">
                我的表格一览
            </div>
            <ol class="am-breadcrumb">
                <li><a href="./index.php" class="am-icon-home">首页</a></li>
                <li class="am-active">我的表格一览</li>
            </ol>
            <div class="tpl-portlet-components">
                <div class="portlet-title">
                    <div class="caption font-green bold">
                        <span class="am-icon-code"></span> 列表
                    </div>
                    <div class="tpl-portlet-input tpl-fz-ml">
                        <div class="portlet-input input-small input-inline">
                            <div class="input-icon right">
                                <i class="am-icon-search"></i>
                                <input type="text" class="form-control form-control-solid" placeholder="搜索..."></div>
                        </div>
                    </div>


                </div>
                <?php
                require_once './core/admin-sql.php';
                $sql = new AdminSql();
                $result_array = $sql->searchAllUidForms($_SESSION['uid']);
                if ($result_array[0] > 0) {
                    $num_ra = count($result_array[1]);
                    $new_form_id = $result_array[1][0] + 1;
                } else {
                    $new_form_id = 1;
                }
                ?>
                <div class="tpl-block">
                    <div class="am-g">
                        <div class="am-u-sm-12 am-u-md-6">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-success"
                                            onclick="addNewForm(<?= $_SESSION['uid'] ?>, <?= $new_form_id ?>)"><span
                                                class="am-icon-plus"></span> 新增
                                    </button>
                                    <?php
                                    if (isset($_GET['pid'])) {
                                        $poUrl = $sql->sPoUrl($_SESSION['uid'], $_GET['pid']);
                                    } else {
                                        $poUrl = 0;
                                    }
                                    ?>
                                    <button type="button" class="am-btn am-btn-default am-btn-secondary"
                                            onclick="look_poster(<?= $_SESSION['uid'] ?>, '<?= $poUrl ?>')">
                                        <span class="am-icon-save"></span> 查看海报
                                    </button>
                                    <button type="button" class="am-btn am-btn-default am-btn-warning"
                                            onclick="look_form(<?= $_SESSION['uid'] ?>)"><span
                                                class="am-icon-archive"></span> 查看表格
                                    </button>
                                    <button type="button" class="am-btn am-btn-default am-btn-danger"><span
                                                class="am-icon-trash-o"></span> 删除
                                    </button>
                                </div>
                            </div>
                        </div>
                        <div class="am-u-sm-12 am-u-md-3">
                            <div class="am-form-group">
                                <select id="select-poster-id" data-am-selected="{btnSize: 'sm'}"
                                        onchange="changeForm()">
                                    <option value="all">所有表格</option>
                                    <?php
                                    if (isset($_GET['pid'])) {
                                        $pid = $_GET['pid'];
                                        if ($pid === 'all') {
                                            if ($result_array[0] > 0) {
                                                for ($i = 0; $i < $result_array[0]; $i++) {
                                                    ?>
                                                    <option value="<?= $result_array[1][$i] ?>"><?= $result_array[1][$i] ?></option>
                                                    <?php
                                                }
                                            }
                                        } else {
                                            if ($result_array[0] > 0) {
                                                for ($i = 0; $i < $result_array[0]; $i++) {
                                                    if ($pid === $result_array[1][$i]) {
                                                        ?>
                                                        <option value="<?= $result_array[1][$i] ?>"
                                                                selected="selected"><?= $result_array[1][$i] ?></option>
                                                        <?php
                                                    } else {
                                                        ?>
                                                        <option value="<?= $result_array[1][$i] ?>"><?= $result_array[1][$i] ?></option>
                                                        <?php
                                                    }
                                                }
                                            }
                                        }
                                    } else {
                                        if ($result_array[0] > 0) {
                                            for ($i = 0; $i < $result_array[0]; $i++) {
                                                ?>
                                                <option value="<?= $result_array[1][$i] ?>"><?= $result_array[1][$i] ?></option>
                                                <?php
                                            }
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="am-u-sm-12 am-u-md-3">
                            <div class="am-input-group am-input-group-sm">
                                <?php
                                if (isset($_GET['search'])) {
                                    ?>
                                    <input type="text" class="am-form-field" value="<?= $_GET['search'] ?>">
                                    <?php
                                } else {
                                    ?>
                                    <input type="text" class="am-form-field">
                                    <?php
                                }
                                ?>
                                <span class="am-input-group-btn">
                                <?php
                                if (isset($_GET['pid'])) {
                                    ?>
                                    <button class="am-btn  am-btn-default am-btn-success tpl-am-btn-success am-icon-search"
                                            type="button" onclick="searchNum('<?= $_GET['pid'] ?>')"></button>
                                    <?php
                                } else {
                                    ?>
                                    <button class="am-btn  am-btn-default am-btn-success tpl-am-btn-success am-icon-search"
                                            type="button" onclick="searchNum('all')"></button>
                                    <?php
                                }
                                ?>
          </span>
                            </div>
                        </div>
                    </div>
                    <div class="am-g">
                        <div class="am-u-sm-12">
                            <form class="am-form">
                                <table class="am-table am-table-striped am-table-hover table-main">
                                    <thead>
                                    <tr>
                                        <th class="table-check"><input type="checkbox" class="tpl-table-fz-check"></th>
                                        <th class="table-id">ID</th>
                                        <th class="table-title">标题</th>
                                        <th class="table-type">类别</th>
                                        <th class="table-date">提交日期</th>
                                        <th class="table-set">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    if (isset($_GET['pid'])) {
                                        if (isset($_GET['search']))
                                            $result_array_answer = $sql->searchAllUidTidForms($_SESSION['uid'], $_GET['pid'], $_GET['search']);
                                        else
                                            $result_array_answer = $sql->searchAllUidTidForms($_SESSION['uid'], $_GET['pid']);
                                    } else {
                                        if (isset($_GET['search']))
                                            $result_array_answer = $sql->searchAllUidTidForms($_SESSION['uid'], 0, $_GET['search']);
                                        else
                                            $result_array_answer = $sql->searchAllUidTidForms($_SESSION['uid'], 0);
                                    }
                                    if ($result_array_answer[0] > 0) {
                                        if (isset($_GET['p'])) {
                                            $p = $_GET['p'];
                                            for ($i = 0; $i < 5; $i++) {
                                                if ($result_array_answer[0] > $i + ($p - 1) * 5) {
                                                    $n = $i + ($p - 1) * 5;
                                                    ?>
                                                    <tr>
                                                        <td><input type="checkbox"></td>
                                                        <td><?= $result_array_answer[1][$n][0] ?></td>
                                                        <td>
                                                            <a href="../showForm.php?cid=<?= $_SESSION['uid'] ?>&pid=<?= $result_array_answer[1][$n][2] ?>&uid=<?= $result_array_answer[1][$n][0] ?>"
                                                               target="_blank">无标题</a>
                                                        </td>
                                                        <td>default</td>
                                                        <td class=""><?= date('Y年m月d日 H:i:s', $result_array_answer[1][$n][1]) ?></td>
                                                        <td>
                                                            <div class="am-btn-toolbar">
                                                                <div class="am-btn-group am-btn-group-xs">
                                                                    <button class="am-btn am-btn-default am-btn-xs am-text-danger">
                                                            <span class="am-icon-trash-o">
                                                            </span>
                                                                        删除
                                                                    </button>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <?php
                                                }
                                            }
                                        } else {
                                            for ($i = 0; $i < 5; $i++) {
                                                if ($result_array_answer[0] > $i) {
                                                    ?>
                                                    <tr>
                                                        <td><input type="checkbox"></td>
                                                        <td><?= $result_array_answer[1][$i][0] ?></td>
                                                        <td>
                                                            <a href="../showForm.php?cid=<?= $_SESSION['uid'] ?>&pid=<?= $result_array_answer[1][$i][2] ?>&uid=<?= $result_array_answer[1][$i][0] ?>"
                                                               target="_blank">无标题</a>
                                                        </td>
                                                        <td>default</td>
                                                        <td class=""><?= date('Y年m月d日 H:i:s', $result_array_answer[1][$i][1]) ?></td>
                                                        <td>
                                                            <div class="am-btn-toolbar">
                                                                <div class="am-btn-group am-btn-group-xs">
                                                                    <button class="am-btn am-btn-default am-btn-xs am-text-danger">
                                                            <span class="am-icon-trash-o">
                                                            </span>
                                                                        删除
                                                                    </button>
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <?php
                                                }
                                            }
                                        }
                                    }
                                    ?>
                                    </tbody>
                                </table>
                                <div class="am-cf">

                                    <div class="am-fr">
                                        <ul class="am-pagination tpl-pagination">

                                            <?php
                                            if (isset($_GET['pid'])) {
                                                $pid = $_GET['pid'];
                                                if (isset($_GET['p'])) {
                                                    $p = $_GET['p'];
                                                    if ($p == 1) {
                                                        ?>
                                                        <li class="am-disabled"><a href="#">«</a></li>
                                                        <?php
                                                    } else {
                                                        ?>
                                                        <li><a
                                                                    href="./table-font-list.php?pid=<?= $pid ?>&p=<?= $p - 1 ?>">«</a>
                                                        </li>
                                                        <?php
                                                    }
                                                    for ($j = $p - 2; $j < $p; $j++) {
                                                        if ($j > 0) {
                                                            ?>
                                                            <li><a
                                                                        href="./table-font-list.php?pid=<?= $pid ?>&p=<?= $j ?>"><?= $j ?></a>
                                                            </li>
                                                            <?php
                                                        }
                                                    }
                                                    ?>
                                                    <li class="am-active">
                                                        <a href="./table-font-list.php?pid=<?= $pid ?>&p=<?= $p ?>"><?= $p ?></a>
                                                    </li>
                                                    <?php
                                                    for ($j = $p + 1; $result_array_answer[0] / 5 > $j - 1; $j++) {
                                                        ?>
                                                        <li>
                                                            <a href="./table-font-list.php?pid=<?= $pid ?>&p=<?= $j ?>"><?= $j ?></a>
                                                        </li>
                                                        <?php
                                                    }
                                                    ?>
                                                    <?php
                                                    if ($p < ($result_array_answer[0] / 5)) {
                                                        ?>
                                                        <li>
                                                            <a href="./table-font-list.php?pid=<?= $pid ?>&p=<?= $p + 1 ?>">»</a>
                                                        </li>
                                                        <?php
                                                    } else {
                                                        ?>
                                                        <li class="am-disabled"><a href="#">»</a></li>
                                                        <?php
                                                    }
                                                } else {
                                                    ?>
                                                    <li class="am-disabled"><a href="#">«</a></li>
                                                    <?php
                                                    for ($i = 0; $i < ($result_array_answer[0] / 5) && $i < 5; $i++) {
                                                        if ($i == 0) {
                                                            ?>
                                                            <li class="am-active">
                                                                <a href="./table-font-list.php?pid=<?= $pid ?>&p=1">1</a>
                                                            </li>
                                                            <?php
                                                        } else {
                                                            ?>
                                                            <li>
                                                                <a href="./table-font-list.php?pid=<?= $pid ?>&p=<?= $i + 1 ?>"><?= $i + 1 ?></a>
                                                            </li>
                                                            <?php
                                                        }
                                                    }
                                                    if ($result_array_answer[0] > 5) {
                                                        ?>
                                                        <li><a href="./table-font-list.php?pid=<?= $pid ?>&p=2">»</a>
                                                        </li>
                                                        <?php
                                                    } else {
                                                        ?>
                                                        <li class="am-disabled"><a href="#">»</a></li>
                                                        <?php
                                                    }
                                                }
                                            } else {
                                                if (isset($_GET['p'])) {
                                                    $p = $_GET['p'];
                                                    if ($p == 1) {
                                                        ?>
                                                        <li class="am-disabled"><a href="#">«</a></li>
                                                        <?php
                                                    } else {
                                                        ?>
                                                        <li>
                                                            <a href="./table-font-list.php?p=<?= $p - 1 ?>">«</a>
                                                        </li>
                                                        <?php
                                                    }
                                                    for ($j = $p - 2; $j < $p; $j++) {
                                                        if ($j > 0) {
                                                            ?>
                                                            <li>
                                                                <a href="./table-font-list.php?p=<?= $j ?>"><?= $j ?></a>
                                                            </li>
                                                            <?php
                                                        }
                                                    }
                                                    ?>
                                                    <li class="am-active">
                                                        <a href="./table-font-list.php?p=<?= $p ?>"><?= $p ?></a>
                                                    </li>
                                                    <?php
                                                    for ($j = $p + 1; $result_array_answer[0] / 5 > $j - 1; $j++) {
                                                        ?>
                                                        <li>
                                                            <a href="./table-font-list.php?p=<?= $j ?>"><?= $j ?></a>
                                                        </li>
                                                        <?php
                                                    }
                                                    ?>
                                                    <?php
                                                    if ($p < ($result_array_answer[0] / 5)) {
                                                        ?>
                                                        <li><a href="./table-font-list.php?p=<?= $p + 1 ?>">»</a>
                                                        </li>
                                                        <?php
                                                    } else {
                                                        ?>
                                                        <li class="am-disabled"><a href="#">»</a></li>
                                                        <?php
                                                    }
                                                } else {
                                                    ?>
                                                    <li class="am-disabled"><a href="#">«</a></li>
                                                    <?php
                                                    for ($i = 0; $i < ($result_array_answer[0] / 5) && $i < 5; $i++) {
                                                        if ($i == 0) {
                                                            ?>
                                                            <li class="am-active">
                                                                <a href="./table-font-list.php?p=1">1</a>
                                                            </li>
                                                            <?php
                                                        } else {
                                                            ?>
                                                            <li>
                                                                <a href="./table-font-list.php?p=<?= $i + 1 ?>"><?= $i + 1 ?></a>
                                                            </li>
                                                            <?php
                                                        }
                                                    }
                                                    if ($result_array_answer[0] > 5) {
                                                        ?>
                                                        <li><a href="./table-font-list.php?p=2">»</a>
                                                        </li>
                                                        <?php
                                                    } else {
                                                        ?>
                                                        <li class="am-disabled"><a href="#">»</a></li>
                                                        <?php
                                                    }
                                                }
                                            }
                                            ?>
                                            <!--                                        <li class="am-disabled"><a href="#">«</a></li>-->
                                            <!--                                        <li class="am-active"><a href="#">1</a></li>-->
                                            <!--                                        <li><a href="#">2</a></li>-->
                                            <!--                                        <li><a href="#">3</a></li>-->
                                            <!--                                        <li><a href="#">4</a></li>-->
                                            <!--                                        <li><a href="#">5</a></li>-->
                                            <!--                                        <li><a href="#">»</a></li>-->

                                        </ul>
                                    </div>
                                </div>
                                <hr>

                            </form>
                        </div>

                    </div>
                </div>
                <div class="tpl-alert"></div>
            </div>


        </div>

    </div>


    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/amazeui.min.js"></script>
    <script src="assets/js/app.js"></script>
    <script src="./ajax/ajax-post.js"></script>
    </body>

    </html>

<?php
require_once '../footer.php';